import { NgxMonacoEditorConfig } from "ngx-monaco-editor";

export const MonacoConfig: NgxMonacoEditorConfig = {
  baseUrl: "assets", // configure base path for monaco editor
  defaultOptions: { scrollBeyondLastLine: false }, // pass default options to be used
  onMonacoLoad: monacoOnLoad
};

export function monacoOnLoad() {
  // here monaco object will be available as window.monaco use this function to extend monaco editor functionalities.
  // register Monaco languages
  monaco.languages.register({
    id: "safenl",
    aliases: ["Safenl", "safenl", "SafeNL"],
    extensions: [".safenl"],
    mimetypes: ["text/safenl"]
  });

  this.obj = {
    keywords: ['intersect', 'imply', 'exclude', 'trigger', 'terminate', 'permit',
      'disallow', 'coincide', 'forbid', 'within', 'in'],
    times: ['h', 'min', 'ms', 's'],
    csType: ['and', 'or'],
    ignoreCase: true,
    tokenizer: {
      root: [
        [/[a-z_][\w\-\.']*/, {
          cases: {
            '@keywords': { token: 'safenl-key' },
            '@times': { token: 'time' },
            '@csType': { token: 'composite-complex-type' }
          }
        }]
      ]
    }
  };
  monaco.languages.setMonarchTokensProvider('safenl', this.obj);
  monaco.editor.defineTheme('safenlTheme', {
    base: 'vs',
    inherit: false,
    rules: [
      { token: 'safenl-key', foreground: '#4B0082' },
      { token: 'time', foreground: '#EE2C2C' },
      { token: "composite-complex-type", foreground: '#4B0082' }
    ],
    colors: {
      // 'editor.background':'#f4f4f4',
      'editorLineNumber.foreground': '#222222',
      'editor.lineHighlightBackground': '#f4f4f4',
    }
  });
  // monaco.languages.register({
  //     id: 'json',
  //     extensions: ['.json', '.bowerrc', '.jshintrc', '.jscsrc', '.eslintrc', '.babelrc'],
  //     aliases: ['JSON', 'json'],
  //     mimetypes: ['application/json'],
  // });

  // // register Monaco languages
  // monaco.languages.register({
  //     id: 'typescript',
  //     extensions: ['.ts', '.tsc'],
  //     aliases: ['TYPESCRIPT', 'typescript'],
  //     mimetypes: ['text/x-typescript'],
  // });
}
